<?php

class BorrowModel extends Model{
	//分页返回所有的借阅数据
	//查询借阅日志(可以用在综合查询里面)
	public function getAllBorrow($offset,$pagesize){
		$sql="SELECT tb_borrow.id,tb_borrow.borrowTime,tb_borrow.backTime,
				tb_borrow.operator,tb_borrow.ifback,tb_bookinfo.bookname,tb_reader.name,tb_reader.barcode  
				FROM `tb_borrow` 
				JOIN tb_bookinfo 
				ON tb_borrow.bookid=tb_bookinfo.id 
				JOIN tb_reader ON tb_borrow.readerid=tb_reader.id 
				order by id desc limit {$offset},{$pagesize}";
		return $this->db->getAll($sql);
	}
	
	//显示一位读者的未还信息
	/**
	 * 
	 * @param int $readerid
	 * @return  array Ambigous <$list, multitype:multitype: >
	 */
	public function getOneReaderBorrow($readerid){
		$sql="SELECT tb_borrow.id,tb_borrow.borrowTime,tb_borrow.backTime,
		tb_borrow.operator,tb_borrow.ifback,tb_bookinfo.bookname,tb_reader.name
		FROM `tb_borrow`
		JOIN tb_bookinfo
		ON tb_borrow.bookid=tb_bookinfo.id
		JOIN tb_reader ON tb_borrow.readerid=tb_reader.id
		where readerid={$readerid} and ifback=0";
		return $this->db->getAll($sql);
	}
	
	//获取该图书的最大可借天数
	/**
	 * 
	 * @param int $bookid 图书的id
	 * @返回该图书id的类型和最大可借天数的二维数组
	 */
	public function getBookBorrowDays($bookid){
		$sql="SELECT tb_bookinfo.id AS bookid,tb_booktype.typename,tb_booktype.days 
				FROM `tb_bookinfo` INNER JOIN tb_booktype 
				ON tb_bookinfo.typeid=tb_booktype.id 
				where tb_bookinfo.id={$bookid}";
		return $this->db->getRow($sql);
	}
}